package com.cokoyan.game.afts;

import android.graphics.Bitmap;
import android.graphics.Canvas;

public class SpriteAnimated {
	private Bitmap []sprite;
	private int cFrame,mFrame;
	
	private int x,y;
	private int height,weight;
	
	private int fps;
	private long cTime,mTime;
	
	private boolean finished;
	
	public SpriteAnimated(Bitmap []sprite, int x, int y, int height, int weight, int mFrame, int fps){
		this.sprite = sprite;
		this.x = x;
		this.y = y;
		this.height = height;
		this.weight = weight;
		this.mFrame = mFrame;
		this.cFrame = 0;
		this.fps = fps;
		this.mTime = 1000/this.fps;
		this.cTime = 0;
		this.finished = false;
	}
	
	public void Draw(Canvas canvas){
		if(GameTime.getTime()>cTime+mTime){
			if(cFrame<mFrame){ 
				cFrame++; 
			}
			if(cFrame==mFrame){
				finished=true;
			}
			cTime = GameTime.getTime();
		}
		if(!finished){
			canvas.drawBitmap(this.sprite[cFrame], this.x-(this.height/2)+8, this.y-(this.weight/2)+12, null);
		}
	}
	
	public boolean isFinish(){
		return this.finished;
	}
}
